package com.zyzo.demo.appengine.server;

import org.restlet.resource.ServerResource;

import com.zyzo.demo.appengine.model.ServerReponse;
import com.zyzo.demo.appengine.model.UserDao;

public class UserutilsController extends ServerResource implements UserutilsControllerInterface {

	
	@Override
	public ServerReponse action() 
	{
		ServerReponse sr = null ;
		String action = (String) getRequest().getAttributes().get("action");
		switch( Integer.parseInt(action) )
		{
			case 1 :
					sr = this.countUsers();
					break;
					
			default:sr = new ServerReponse( ServerReponse.STATUS_ERR , "unknown action '"+action+"'");
					break;
		}
		return sr;
	}

	
	private ServerReponse countUsers()
	{
		int c=  UserDao.getInstance().countUsers();
		ServerReponse sr = new ServerReponse( ServerReponse.STATUS_OK , c+"" );
		
		return sr;
	}
	 
}
